package com.hjx.datareporter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hjx.objectassert.model.CreditCardAllData;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ReportService {

    private static final ExecutorService pool = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

        List<CreditCardAllData> data = JSON.parseArray(FileUtils.readFileToString(new File("D:\\ws\\test\\src\\test\\resources\\另一个人.txt"), "UTF-8"), CreditCardAllData.class);

//        List<CreditCardAllData> data1 = new ArrayList<>();
//        data1.addAll(data);
//        data1.addAll(data);

        List<Future<JSONObject>> futures = new ArrayList<>();

        data.forEach(cardData -> {
            futures.add(pool.submit(new Reporter<JSONObject>(cardData, pool)));
        });
        pool.shutdown();

        List<JSONObject> results = new ArrayList<>();
        //合并结果
        for (Future<JSONObject> future : futures){
            results.add(future.get());
        }

        System.out.println(JSON.toJSONString(results));

    }

}
